%f = fopen('log.txt','w');
% 1	Retail
% 2	Insurance
% 3	Real estate
% 4	IT
% 5	Oil & Gas
% 6	Financial Service
% 7	Electricity
% 8	Hospitality
% 9	Heavy Industry
% 10	Household Products
% 11	Chemistry
% 12	Bank
% 13	Automobile
% 14	Natural Resources
% 15	FMCG
% 16	Media
% 17	Telecom
% 18	Construction
% 19	Healthcare

%%
fi = fastat('all year', 12);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_bank` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,10) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 6);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_financial` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,11) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 2);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_insurance` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,12) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 1);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_retail` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 3);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_real_estate` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 4);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_it` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 5);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_oil_gas` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 7);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_electricity` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 8);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_hospitality` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 9);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_heavy_industry` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 10);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_household_product` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 11);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_chemistry` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 13);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_automobile` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 14);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_natural_resource` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 15);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_fmcg` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 16);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_media` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 17);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_telecom` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 18);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_construction` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%
fi = fastat('all year', 19);
para1 = {'mean';'std';'kurtosis';'skewness';'median';'max';'min';'95th quantile';'5th quantile'};
moi= 'it''s easy';
num_copy = length(fi)/9;
para = repmat(para1,num_copy,1);
for i = 1:length(fi)
    sql = ['INSERT INTO `fundamental_stat_healthcare` VALUES (%s,%d,%d,%d' ...
                repmat(',%f',1,13) ... 
                ')'];
    stat = strcat(moi(3), para{i},moi(3));
    sql = sprintf(sql,stat,fi(i,:));
    %fprintf(f,'Importing ...');
    get_info_from_database('sql',sql);
    %fprintf(f,'Done !\n');
end
clear all
%%

%fclose(f);
%Statistics of sector
%sector = get_info_from_database('sector-info', 'all');
%n = length(sector);
% for i=1:n;
%     fprintf('Running %d / 20 ... \n',i);
%     sheet_name = sprintf('statFA sector %d',i);
%     fas = fastat('all year',i);
%     fprintf('Running %d / 20 ... \n',i);
%     sheet_name = sprintf('statFA sector %d',i);
% %     xlswrite('Industry statistics',fas,sheet_name);
%     xlswrite(sheet_name,fas);
%     
% end